import rxAjax from '@/assets/js/ajax.js';
import {Util} from '@lowcode/jpaas-common-lib';

//接口API表 api接口
export const SysInterfaceApiApi = {};

SysInterfaceApiApi.baseUrl= '/api-system/system/core/sysInterfaceApi';
SysInterfaceApiApi.exportUrl= SysInterfaceApiApi.baseUrl + '/listExport';

//查询列表
SysInterfaceApiApi.query=function (parameter) {
  var url= SysInterfaceApiApi.baseUrl + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

SysInterfaceApiApi.queryByClassificationId=function(classId){
    var url = SysInterfaceApiApi.baseUrl + '/queryByClassificationId?classId='+classId;
    return rxAjax.get(url);
}

SysInterfaceApiApi.queryByProjectId=function(projectId){
    var url = SysInterfaceApiApi.baseUrl + '/queryByProjectId?projectId='+projectId;
    return rxAjax.get(url);
}

/**
* 获取单记录
* @param pkId
* @returns {*}
*/
SysInterfaceApiApi.get =function(pkId) {
  var url= SysInterfaceApiApi.baseUrl + '/get?pkId=' + pkId;
  return rxAjax.get(url);
}

//保存数据
SysInterfaceApiApi.save =function(parameter) {
  var url= SysInterfaceApiApi.baseUrl + '/save';
  return rxAjax.postJson(url,parameter);
}

//删除数据
SysInterfaceApiApi.del =function(parameter) {
  var url= SysInterfaceApiApi.baseUrl + '/del';
  return rxAjax.postUrl(url,parameter);
}

//测试接口
SysInterfaceApiApi.executeTestApi=function(parameter){
    var url = SysInterfaceApiApi.baseUrl + '/executeTestApi';
    return rxAjax.postJson(url,parameter);
}

SysInterfaceApiApi.export=function(classId,type,apiIds){
    classId=Util.encryptWord(classId);
    type=Util.encryptWord(type);
    apiIds=Util.encryptWord(apiIds);
    window.location.href='/api/api-system/system/core/sysInterfaceApi/doExport?classId='+classId+'&type='+type+'&apiIds='+apiIds;
}

SysInterfaceApiApi.getInterfaceImportTypeList=function(){
    var url = SysInterfaceApiApi.baseUrl + '/getInterfaceImportTypeList';
    return rxAjax.get(url);
}

export  default SysInterfaceApiApi;

